Skip to content

Add sbrk syscall and heap management from ch4 address space design#169

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-48653639-308248461-7cf13092-be5e-4fb3-9a5e-44ddf7502aed
Draft

Add sbrk syscall and heap management from ch4 address space design#169
Copilot wants to merge 2 commits intomainfrom
copilot/fix-48653639-308248461-7cf13092-be5e-4fb3-9a5e-44ddf7502aed

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 30, 2026

The ch4 branch's user-mode address space layout includes dynamic heap management via sbrk, but the main branch was missing the entire heap infrastructure. This adds it.

User address space layout (ch4 design)

[ELF segments] [guard page] [user stack] [heap →] ... [TrapContext] [Trampoline]

The heap starts at ustack_base + USER_STACK_SIZE, initialized as an empty MapArea, and grows/shrinks via sbrk.

Kernel changes

  • mm/memory_set.rs: Add shrink_to / append_to on both MemorySet and MapArea to support page-granular heap resize
  • task/process.rs: Add heap_bottom + program_brk to ProcessControlBlockInner; add change_program_brk() method; initialize empty heap MapArea in new() and exec(), copy fields in fork()
  • task/mod.rs: Expose change_program_brk(size: i32) -> Option<usize> as a public API
  • syscall/mod.rs: Add SYSCALL_SBRK = 214 and dispatch to sys_sbrk
  • syscall/process.rs: Implement sys_sbrk

User-space changes

  • user/src/syscall.rs: Add SYSCALL_SBRK + sys_sbrk
  • user/src/task.rs: Add sbrk(size: i32) -> isize wrapper
  • user/src/bin/sbrk_test.rs: Add test covering allocate, write, bulk grow, bulk shrink, and underflow guard

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/rcore-os/riscv/commits/HEAD
    • Triggering command: /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build (http block)
    • Triggering command: /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build --release rustc /lib64/ld-linux-x86-64.so.2 -pie -z ib.rs -fuse-ld=lld -z relro -o n-li�� n-linux-gnu/lib/OUTPUT debug/build/os-5-d debug/build/os-5168.63.129.16 debug/build/os-5/home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/lib/--edition=2015 debug/build/os-5-plugin debug/build/os-5/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so debug/build/os-5-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper (http block)
  • https://api.github.com/repos/rcore-os/virtio-drivers/commits/4ee80e5
    • Triggering command: /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build (http block)
  • https://api.github.com/repos/yfblock/lose-net-stack/commits/db42380
    • Triggering command: /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Analyze user space application address space layout in ch4 branch Add sbrk syscall and heap management from ch4 address space design Mar 30, 2026
Copilot AI requested a review from chyyuu March 30, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants